package main;

import java.awt.EventQueue;

import javax.swing.JOptionPane;

import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import logic.ModsLoader;
import ui.PanelLogin;

public class Main
{
	private final static String			LogFilePath		= new String("Logging.txt");
	private static FileHandler			fileTxt				= null;
	private static SimpleFormatter	formatterTxt	= null;
	public final static Logger	LOGGER						= Logger.getLogger(Logger.GLOBAL_LOGGER_NAME);

	/**
	 * Launch the application.
	 */
	public static void main(String[] args)
	{
		// Init Logger
		try
		{
			LOGGER.setLevel(Level.INFO);
			fileTxt = new FileHandler(LogFilePath, true);
			formatterTxt = new SimpleFormatter();
			fileTxt.setFormatter(formatterTxt);
			LOGGER.addHandler(fileTxt);
		}
		catch (Exception e)
		{
			JOptionPane.showMessageDialog(null, e.getMessage());
		}

		// lets run app now.
		EventQueue.invokeLater(new Runnable()
		{
			public void run()
			{
				try
				{
					// check modsFilePath and launch Login if ok
					if (ModsLoader.getInstance().loadConfigIsOk())
						new PanelLogin();
					else
						JOptionPane.showMessageDialog(null, "Config error: probably wrong File Path to allods mods.txt file. See README.txt for more details.");
				}
				catch (Exception e)
				{
					e.printStackTrace();
				}
			}
		});
	}
}
